import type {GenData} from "@/pages/system/tool/gen/type";
import type {ReactNode} from "react";
import type {UseFetchDataAction} from "@ant-design/pro-table/es/typing";
import {Button, Space, Tabs} from "antd";
import type {ProColumns} from "@ant-design/pro-table";
import {history} from 'umi';
import type {OptionActions} from "@/type/type";
import type {ModalFormProps} from "@ant-design/pro-form/lib/layouts/ModalForm";
import {ModalForm} from "@ant-design/pro-form";

// @ts-ignore
const columns: ProColumns<GenData> = (optionAction: OptionActions & { downloadGenCode: (ids: number[]) => void, getPreviewCode: (id: number) => void }, items: any[]) => {
  return [
    {
      dataIndex: "index",
      valueType: "index",
    },
    {
      title: "表",
      dataIndex: "tableName",
      align: 'center',
      render: (text: ReactNode, record: GenData, index: number, action: UseFetchDataAction<GenData>) => {
        const modalProps: ModalFormProps = {
          trigger: <Button type="link" onClick={() => optionAction.getPreviewCode(record.id)}>{text}</Button>,
          width: 1300,
          title: "预览代码",
          submitter: false
        }
        return (
          <ModalForm {...modalProps}>
            <Tabs  type={"card"} items={items}/>
          </ModalForm>
        )
      }
    },
    {
      title: "数据库",
      dataIndex: "databaseName",
      align: "center",
    },
    {
      title: "描述",
      dataIndex: "comment",
      align: "center",
      hideInSearch: true
    },
    {
      title: "导入时间",
      dataIndex: "createTime",
      align: "center",
      hideInSearch: true
    },
    {
      title: "更新时间",
      dataIndex: "updateTime",
      align: "center",
      hideInSearch: true,
    },
    {
      title: "操作",
      valueType: 'option',
      align: "center",
      key: "option",
      width: "200px",
      render: (text: ReactNode, record: GenData, index: number, action: UseFetchDataAction<GenData>) => {
        return (
          <Space>
            <Button type="link" onClick={() => {
              // @ts-ignore
              history.push({
                pathname: '/system/tool/gen/detail',
                query: {
                  id: record.id
                }
              });
            }
            }>查看</Button>
            <Button type="link" onClick={() => optionAction.other([record.tableName])}>同步</Button>
            <Button type="link" onClick={() => optionAction.downloadGenCode([record.id])}>生成代码</Button>
          </Space>
        )
      }
    }
  ]
}


export default columns;
